#ifndef __STR_H
#define __STR_H
#include "stdtype.h"

/**
 * this function will iterate the specified string
 * @prototype: void str_foreach (mx_cstring_pt, <char* pc>, {...});
 */
#define str_foreach(str, pc, ...) {  \
    mx_string_pt pc;    \
    for (pc = str; *pc != '\0'; pc++) {    \
        __VA_ARGS__ \
    }   \
}

/**
 * this function will iterate the specified string with index
 * @prototype: void str_foreachi (mx_cstring_pt, <char* pc> <mx_usize_t i>, {...});
 */
#define str_foreachi(str, pc, i, ...) {  \
    mx_string_pt pc;    \
    mx_usize_t i;    \
    for (pc = str, i = 0; *pc != '\0'; pc = &(str)[++i]) {    \
        __VA_ARGS__ \
    }   \
}

/* get the string length */
mx_usize_t str_getlen (mx_cstring_pt s);
/* check whether the string is empty ("") */
mx_bool_t str_isempty (mx_cstring_pt s);
/* check whether the string is integer */
mx_bool_t str_isinteger (mx_cstring_pt s);
/* check whether the specified two strings are equal */
mx_bool_t str_isequal (mx_cstring_pt s1, mx_cstring_pt s2);
/* copy string */
void str_copy (mx_string_pt dst, mx_cstring_pt src);
/* copy string within the specified size */
void str_copyn (mx_string_pt dst, mx_cstring_pt src, mx_usize_t dcnt);

/* count the number of specified char in target string */
mx_usize_t str_cn (mx_cstring_pt src, char c);
/* find the specified char in target string, forward lookup */
mx_size_t str_ci (mx_cstring_pt src, char c);
/* find the specified char in target string, reverse lookup */
mx_size_t str_cir (mx_cstring_pt src, char c);
/* count the number of specified string in target string */
mx_usize_t str_sn (mx_cstring_pt src, mx_cstring_pt s);
/* find the specified string in target string, forward lookup */
mx_size_t str_si (mx_cstring_pt src, mx_cstring_pt s);
/* find the specified string in target string, reverse lookup */
mx_size_t str_sir (mx_cstring_pt src, mx_cstring_pt s);

/* delete the before and after spaces in target string */
mx_string_pt str_trim (mx_string_pt s);
/* split the string using the specified char */
mx_usize_t str_splitc (mx_string_pt src, char c, mx_string_pt* arr, mx_usize_t arrlen);
/* split the string using the specified char and trim each string */
mx_usize_t str_splitc_trim (mx_string_pt src, char c, mx_string_pt* arr, mx_usize_t arrlen);

/* repalce char(s) in the string to another char */
void str_replacec (mx_string_pt src, char f, char t);
/* convent char(s) to upcase in source string */
void str_upcase (mx_string_pt src);
/* convent char(s) to lowcase in source string */
void str_lowcase (mx_string_pt src);

#endif
